import {Navigate, useLocation} from "react-router-dom";
import {getToken} from "../utils/auth.js";
const RouteGuard = (props:any) => {
    const WhiteList = ["/", "/login"];
    const {pathname} = useLocation()
    const token = getToken()
    if (WhiteList.indexOf((pathname ? pathname : "/")) === -1) {
        if (token) {
            return props.children;
        } else {
            return <Navigate to="/login"/>;
        }
    } else {
        return props.children;
    }
}

export default RouteGuard
